package ru.ksu.ktk.diploma.sdi.mapping;

import java.util.*;

import ru.ksu.ktk.diploma.sdi.mapping.thesauri.ThesauriDescriptor;

/**
 * @author coldflame
 */
public class Triple {
    private static final String SPO_FORMATTED = "%s-%s-%s";
    /**
     * class-domain URI
     */
    private String domainUri;
    /**
     * property URI of class-domain and class-range
     */
    private String pathUri;
    /**
     * class-range URI
     */
    private String rangeUri;
    /**
     * rdfs:label
     */
    private String rdfsLabel;
    /**
     * thesauri descriptors of rdfs:label string
     */
    private List<ThesauriDescriptor> descriptors;

    public Triple(String domainUri, String pathUri, String rangeUri) {
        this.domainUri = domainUri;
        this.pathUri = pathUri;
        this.rangeUri = rangeUri;
    }

    public String getDomainUri() {
        return domainUri;
    }

    public void setDomainUri(String domainUri) {
        this.domainUri = domainUri;
    }

    public String getPathUri() {
        return pathUri;
    }

    public void setPathUri(String pathUri) {
        this.pathUri = pathUri;
    }

    public String getRangeUri() {
        return rangeUri;
    }

    public void setRangeUri(String rangeUri) {
        this.rangeUri = rangeUri;
    }

    public String getRdfsLabel() {
        return rdfsLabel;
    }

    public void setRdfsLabel(String rdfsLabel) {
        this.rdfsLabel = rdfsLabel;
    }

    public void addDescriptor(ThesauriDescriptor descriptor) {
        this.descriptors.add(descriptor);
    }

    public List<ThesauriDescriptor> getDescriptors() {
        return descriptors;
    }

    public void setDescriptors(List<ThesauriDescriptor> descriptors) {
        this.descriptors = descriptors;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) return true;
        if (!(o instanceof Triple)) return false;
        Triple t = (Triple) o;
        return domainUri.equals(t.getDomainUri()) && pathUri.equals(t.getPathUri()) && rangeUri.equals(t.getRangeUri());
    }

    @Override
    public int hashCode() {
        int result = 17;
        if (domainUri != null){
            result = 31 * result + domainUri.hashCode();
        }
        if (pathUri != null){
            result = 31 * result + pathUri.hashCode();
        }
        if (rangeUri != null){
            result = 31 * result + rangeUri.hashCode();
        }

        return result;
    }

    @Override
    public String toString() {
        return String.format(SPO_FORMATTED, domainUri, pathUri, rangeUri);
    }
}
